/**
 *公共提现窗口
 * @param recordType 类型，1问答分成，2旁听分成
 */
function commonCash(recordType) {
    var title = '';
    if(recordType==1){
        title = '问答分成提现';
    }
    if(recordType==2){
        title = '旁听分成提现';
    }
    parent.layer.open({
        type: 2,
        area: winArea,
        content: baseloaction + '/admin/qa/record/cashWithdrawal?recordType=' + recordType,
        maxmin: true,
        shade: [0.3, '#000'],
        shadeClose: false,
        title: '<strong>'+title+'</strong>',
        btn: ['确认','取消'],
        yes: function (index,layero) {
            var iframeName = layero.find("iframe").attr('name');
            var em = $(parent.window.frames[iframeName].document);
            var accountType = em.find('input[name=accountType]:checked').val();
            var teacherId = em.find("#teacherId").val();
            var recordType =em.find("#recordType").val();
            var realName = em.find("#realName").val();
            if(accountType ==2){//微信
                if(realName == null || $.trim(realName) == ''){
                    icModale(0,'请填写提现账户真实姓名');
                    return;
                }
                parent.layer.close(index);
                //生成微信二维码
                genQRCode(teacherId,recordType,realName);
            }else if(accountType==1) {//支付宝
                var account = em.find("#account").val();
                $.ajax({
                    url:baseloaction +'/admin/qa/cash/zfbCashWithdrawal',
                    type:'post',
                    dataType:'json',
                    data:{
                        'teacherId':teacherId,
                        'account':account,
                        'realName':realName,
                        'recordType':recordType
                    },
                    success:function (result) {
                        icModale(0,result.message);
                        if(result.success==true){
                            parent.layer.close(index);
                        }
                    },
                    error:function (error) {
                        icModale(0,'系统错误，操作失败');
                    }
                });
            }
        },
        btn2: function(index) {
            parent.layer.close(index);
        }
    });
}

/**
 * 生成微信二维码
 * @param teacherId 老师ID
 * @param recordType 记录类型
 * @param realName 账户真实姓名
 */
function genQRCode(teacherId,recordType,realName){
    $.ajax({
        url: baseloaction +'/admin/qa/cash/bindingWeiXin',
        type:'post',
        dataType:'json',
        data:{
            'teacherId':teacherId,
            'recordType':recordType,
            'realName':realName
        },
        success:function(result){
            if(result.success==true){
                var link = result.entity;
                var context = '<div class="text-center"><div id="qrcode"></div><div>扫一扫，绑定提现微信账号</div></div>';
                parent.layer.open({
                    type:1 ,
                    area: ['40%','40%'],
                    skin: 'layui-layer-demo',
                    title: '扫码绑定提现微信账号',
                    content:context,
                    btn: ['确定','取消'],
                    yes: function (index, layero) {
                        parent.layer.close(index);
                    },
                    success:function (layer) {
                        var em = layer.find('#qrcode');
                        try{
                            document.createElement('canvas').getContext('2d');
                            $(em).qrcode({render:"canvas",height:200, width:200,correctLevel:0,text:link});
                        }catch (e){
                            $(em).qrcoverificationOrderStatusde({render:"table",height:200, width:200,correctLevel:0,text:link});
                        }
                    }
                });
            }else{
                icModale(0,result.message);
            }
        },
        error:function (error) {
            icModale(0,'系统错误，绑定提现微信账号失败');
        }
    });
}